package com.zs.grain.ui

import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.xnkj1688.semplibrary.mvvm.BaseViewModel
import com.zs.grain.service.DataService
import com.zs.grain.service.DeviceService
import com.zslibrary.BusMaster.BusNfc
import java.text.SimpleDateFormat
import java.util.*
import javax.inject.Inject
import kotlin.concurrent.schedule

class MaintenanceViewModel @Inject constructor(
    val mApp: Application,
    val mDataService: DataService,
    val mDeviceService: DeviceService
) : BaseViewModel(mApp) {

    val logo = MutableLiveData<String>()
    val title = MutableLiveData<String>()
    val qr = MutableLiveData<String>()
    val isOnline = MutableLiveData<Boolean>()
    val line = MutableLiveData<String>()
    val recentCard = MutableLiveData<String>()
    val currentAuth = MutableLiveData<String>()
    val cAuth = MutableLiveData<String>()
    val time = MutableLiveData<String>()
    private var mTimeTimer: Timer? = null

    init {
        this.startTimeTimer()
        mDeviceService.isMaintenance = true
    }

    fun startTimeTimer() {
        val sdFormatter = SimpleDateFormat("MM-dd HH:mm")
        sdFormatter.timeZone = TimeZone.getTimeZone("GMT+8")
        this.mTimeTimer = Timer()
        this.mTimeTimer?.schedule(1000, 1000) {
            System.currentTimeMillis()
            var date = Date(System.currentTimeMillis())
            time.postValue(sdFormatter.format(date))
        }
    }

    fun insertLog(logContent:String){
        mDataService.insertLog(logContent)
    }
}